import Vue from "vue";
import VueRouter from "vue-router";
import LoginView from "../views/VideoList.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "home",
    redirect: "/list",
  },
  {
    path: "/list",
    name: "list",
    meta: {
      title: "列表",
    },
    component: LoginView,
    // 懒加载页面
    // component: () => import(/* webpackChunkName: "about" */ "@/views/LoginView.vue"),
  },
  // {
  //   path: "/video",
  //   name: "video",
  //   meta: {
  //     title: "视频上传",
  //   },
  //   component: () => import("@/views/VideoView.vue"),
  // },
  {
    path: "/test",
    name: "test",
    meta: {
      title: "测试",
    },
    component: () => import("@/views/Test.vue"),
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

router.beforeEach((to, from, next) => {
  to.meta.title && (document.title = to.meta.title);
  if (to.path === "/login") {
    next();
  } else {
    // 权限控制
    next();
  }
});

export default router;
